package com.gongpingjialoan.adapter.car;

import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.gongpingjialoan.R;
import com.gongpingjialoan.bean.car.DiscountFliterBean;
import com.gongpingjialoan.utility.BaseViewHolder;

import java.util.List;

/**
 * Created by Administrator on 2015/12/15.
 */
public class FilterAdapter extends BaseAdapter {

    private Context mContext;
    private List<DiscountFliterBean> mDiscountFliterBeans;
    private Resources mResources;

    public FilterAdapter(Context context, List<DiscountFliterBean> discountFliterBeans) {
        mContext = context;
        mResources = mContext.getResources();
        mDiscountFliterBeans = discountFliterBeans;
    }

    @Override
    public int getCount() {
        return mDiscountFliterBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return mDiscountFliterBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.discount_filter_item, parent , false);
        }
        TextView titleTextView = BaseViewHolder.get(convertView, R.id.text);
        final DiscountFliterBean discountFliterBean = mDiscountFliterBeans.get(position);
        titleTextView.setText(discountFliterBean.getTitle());
        if(discountFliterBean.isSelect()){
            titleTextView.setBackgroundResource(R.drawable.button_big_bg_normal);
            titleTextView.setTextColor(mResources.getColor(R.color.white));
        }else{
            titleTextView.setBackgroundResource(R.drawable.discount_filter_normal);
            titleTextView.setTextColor(mResources.getColor(R.color.text_title_color));
        }


        return convertView;
    }
}
